package com.dp.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dp.common.annotation.Log;
import com.dp.common.core.controller.BaseController;
import com.dp.common.core.domain.AjaxResult;
import com.dp.common.enums.BusinessType;
import com.dp.system.domain.SysAlarmRule;
import com.dp.system.service.ISysAlarmRuleService;
import com.dp.common.utils.poi.ExcelUtil;
import com.dp.common.core.page.TableDataInfo;

/**
 * 报警规则Controller
 * 
 * @author ruoyi
 * @date 2025-02-10
 */
@RestController
@RequestMapping("/system/rule")
public class SysAlarmRuleController extends BaseController
{
    @Autowired
    private ISysAlarmRuleService sysAlarmRuleService;

    /**
     * 查询报警规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAlarmRule sysAlarmRule)
    {
        startPage();
        List<SysAlarmRule> list = sysAlarmRuleService.selectSysAlarmRuleList(sysAlarmRule);
        return getDataTable(list);
    }

    /**
     * 导出报警规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "报警规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAlarmRule sysAlarmRule)
    {
        List<SysAlarmRule> list = sysAlarmRuleService.selectSysAlarmRuleList(sysAlarmRule);
        ExcelUtil<SysAlarmRule> util = new ExcelUtil<SysAlarmRule>(SysAlarmRule.class);
        util.exportExcel(response, list, "报警规则数据");
    }

    /**
     * 获取报警规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return success(sysAlarmRuleService.selectSysAlarmRuleByRuleId(ruleId));
    }

    /**
     * 新增报警规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "报警规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAlarmRule sysAlarmRule)
    {
        return toAjax(sysAlarmRuleService.insertSysAlarmRule(sysAlarmRule));
    }

    /**
     * 修改报警规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "报警规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAlarmRule sysAlarmRule)
    {
        return toAjax(sysAlarmRuleService.updateSysAlarmRule(sysAlarmRule));
    }

    /**
     * 删除报警规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "报警规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(sysAlarmRuleService.deleteSysAlarmRuleByRuleIds(ruleIds));
    }
}
